package com.example.system.websocket;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
import java.io.IOException;
import java.util.Map;

/**
 * @author hl
 */
public class ServerEncoder implements Encoder.Text<Map> {
    @Override
    public String encode(Map map) throws EncodeException {
        ObjectMapper mapMapper = new ObjectMapper();
        try {
            String json = "";
            json = mapMapper.writeValueAsString(map);
            return json;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "";
        }
    }

    @Override
    public void init(EndpointConfig endpointConfig) {

    }

    @Override
    public void destroy() {

    }
}
